package chapter02;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 
 * 
 * @author insight
 * @since 2021/8/6
 */
public class FileUtil {
    public static final String TEST_FILE_PATH = 
            "chapter02-io/src/main/resources/test.txt";
    private static FileInputStream fileInputStream = null;
    private static FileOutputStream fileOutputStream = null;

    public static FileInputStream getTestFileInputStreamInstance() {
        if (fileInputStream == null) {
            try {
                fileInputStream = new FileInputStream
                        (TEST_FILE_PATH);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        return fileInputStream;
    }

    public static FileOutputStream getTestFileOutputStreamInstance() {
        if (fileOutputStream == null) {
            try {
                fileOutputStream = new FileOutputStream
                        (TEST_FILE_PATH);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        return fileOutputStream;
    }
}